package GreedyAlgorithms;

import java.util.Arrays;
import java.util.Scanner;

/*
有一群孩子+一堆饼干，每个孩子都有一个饥饿度，每个饼干都有一个大小，每个小孩只能吃一个饼干。
求有多少个孩子可以吃饱？
 */
public class 分配问题 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        //直接输入数组
        String childrenInput = sc.nextLine();
        String[] childrenStrings = childrenInput.split(" ");
        int[] children = new int[childrenStrings.length];
        for (int i = 0; i < childrenStrings.length; i++) {
            children[i] = Integer.parseInt(childrenStrings[i]);
        }

        String cookiesInput = sc.nextLine();
        String[] cookiesStrings = cookiesInput.split(" ");
        int[] cookies = new int[cookiesStrings.length];
        for (int i = 0; i < cookiesStrings.length; i++) {
            cookies[i] = Integer.parseInt(cookiesStrings[i]);
        }

        int child = solution(children, cookies);
        System.out.println(child);
    }

    static int solution(int[] children,int[] cookies){
        Arrays.sort(children);
        Arrays.sort(cookies);
        int child=0;//能吃饱孩子的数量
        int cookie=0;//第几个饼干
        while(child<children.length&&cookie<cookies.length){
            if(children[child]<=cookies[cookie++]){
                child++;
            }
        }
        return child;
    }
}
